var date=echartUtil.GetDateStr(0);

//相关业务逻辑
var table1;
var table2;
$(function(){
	page.bindTag();
	page.getAllSearchWhere();
	nameToIdUtil.getProductionDepartment("productionDepartment");
	$("#yestarday").val(date);
});

function dataChange(){
	date=$("#yestarday").val();
}

var page={//页面总变量
		orderPamar:['companyOrderId','factoryId','coustomId','coustomOrderId','orderId'],
		orderList:[],
		bindTag:function(){
			$("#workShop").bind("change",function(){
				deptName=$(this).val();
				page.getMachining(deptName);
			});
			
		    $("#productionDepartment").bind("change",function(){
				var deptId=$("#productionDepartment").val();
				page.getDept(deptId);
			});
		    
		    $("#queryTurnoverBtn").bind("click",function(){
		    	var deptName=$("#workShop option:selected").val();
		    	machining=$("#Machining option:selected").val();
		    	if(deptName==''){
		    		layAlert("请选择车间");
		    		return false;
		    	}
		    	var object=new Object;
				for(var i=0;i<page.orderPamar.length;i++){
					object[page.orderPamar[i]]=$("#"+page.orderPamar[i]).val();
				}
				object.workShop=deptName;
				object.machining=machining;
				object.date=date;
		    	page.getWorkShopMaterial(object);
		    	page.getWorkShopMaterialSumPrice(object);
		    });
		},
		getAllSearchWhere:function(){/**获取所有筛选条件*/
			ajaxUtil.ajaxRuquestNoQuan('companyMaterial/getAllOrderSearchWhere',null,function(data){
				page.orderList=data;
				filterInput.filterView("",page.orderPamar,page.orderList);
			});
		},
		getDept:function(deptId){
			nameToIdUtil.getWorkShopNameAndId("workShop",deptId);
		},
		getMachining:function(workShop){
			ajaxUtil.ajaxRuquest("workshop/getMachining",{"workShop":workShop},function(data){
				var html="<option value=''>请选择</option>";
				for(var i=0;i<data.length;i++){
					html+="<option value='"+data[i]+"'>"+data[i]+"</option>";
				}
				$("#Machining").html(html);
			});
		},
		getWorkShopMaterial:function(object){
			table1=ajaxUtil.dataTablesAjaxNotFxiaction("materialTable",10,"workshop/getWorkShopMaterial",object,[
						{"data":"companyOrderId"},
						{"data":"factoryId"},
						{"data":"customerOrderId"},
						{"data":"materialName"},
						{"data":"model"},
						{"data":"materialType"},
						{"data":"color"},
						{"data":"colorDescription"},
						{"data":"unitPrice"},
//						{"data":"unitPrice",render: function (data,type,row) {
//							return Math.ceil(data * 100)/100;
//						}},
						{"data":"trunoverCount"},
						{"data":"sumPrice"}
//						{"data":"sumPrice",render: function (data,type,row) {
//							return Math.ceil(row.unitPrice * 100)/100 * row.trunoverCount;
//						}}
					]);
			
			
			table2=ajaxUtil.dataTablesAjaxNotFxiaction("materialTableNotCode",10,"workshop/getWorkShopMaterialNotCode",object,[
						{"data":"companyOrderId"},
						{"data":"factoryId"},
						{"data":"customerOrderId"},
						{"data":"model"},
						{"data":"materialType"},
						{"data":"color"},
						{"data":"colorDescription"},
						{"data":"trunoverCount"},
						{"data":"unitPrice", render: function (data,type,row) {
							return "<span style='color:red'>未知</span>";
						}}
						]);
		},
		getWorkShopMaterialSumPrice:function(object){
			ajaxUtil.ajaxRuquest("workshop/getWorkShopMaterialSumPrice",object,function(data){
				if(data==null){
					data=0;
				}
				$("#sumPrice").text("总价格："+data.toFixed(2));
				console.log(data);
			});
		}
}
